//
//  YYLoginViewController.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/7/29.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "YYLoginViewController.h"

@interface YYLoginViewController ()

@end

@implementation YYLoginViewController


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];

}

- (void)viewDidLoad {
    [super viewDidLoad];
//    if (_hasTop) {
//        self.topView.hidden = NO;
//        self.topHight.constant = 44;
//    }else{
//        self.topView.hidden = YES;
//        self.topHight.constant = 0;
//    }
    self.phoneView.layer.borderColor = [UIColor whiteColor].CGColor;
    self.psdView.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.tfPhone addTarget:self action:@selector(tfDidChange:) forControlEvents:UIControlEventAllEvents];
    self.bgImageView.image = DEF_IMAGENAME(@"login_bg");
}

- (void)tfDidChange:(UITextField *)tf{
    if ([tf isEqual:self.tfPhone]) {
        if (tf.text.length>11) {
            tf.text = [tf.text substringToIndex:11];
        }
    }
    
}

- (IBAction)login:(id)sender {
    if (self.tfPhone.text.length!=11) {
        [AlertUtil alertMessage:@"请输入正确格式的手机号码"];
        return;
    }
    if (self.tfPassword.text.length<1) {
        [AlertUtil alertMessage:@"请输入密码"];
        return;
    }
    [RequestOperationManager login_phon:self.tfPhone.text password:self.tfPassword.text Success:^(id result) {
        if (DEF_REQ_SUCCESS) {
            [[NSUserDefaults standardUserDefaults] setObject:result[@"data"][@"uid"] forKey:@"uid"];
            [[NSUserDefaults standardUserDefaults] setObject:self.tfPhone.text forKey:@"phone"];
            [[AppDelegate shareAppDelegate] enterHomePageVC];
        }else{
            
        }
    } failture:^(NSError *error) {
        
    }];
}

-(void)GetheradientColor{
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = self.view.frame;  // 设置显示的frame
    DEF_UICOLOR_FROM_RGB(13, 205, 244, 1);
    gradientLayer.colors = @[(id)DEF_UICOLOR_FROM_RGB(13, 205, 244, 1).CGColor,(id)DEF_UICOLOR_FROM_RGB(85, 231, 197, 1).CGColor];  // 设置渐变颜色
    gradientLayer.startPoint = CGPointMake(0, 0);   //
    gradientLayer.endPoint = CGPointMake(1, 1);     //
    [self.bgImageView.layer addSublayer:gradientLayer];
}

- (IBAction)back:(id)sender {
    [[AppDelegate shareAppDelegate] enterHomePageVC];
}


@end
